package com.zws.cucumber.snapshot;

import com.zws.cucumber.util.colorfullog.ZwsColorfulLogger;
import com.zws.cucumber.var.ZwsVar;
import com.zws.cucumber.var.ZwsVarBlock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class ZwsVarSnapshotManager implements ZwsSnapshotManager<ZwsVarBlock> {

    private static final Logger logger = ZwsColorfulLogger.of(LoggerFactory.getLogger(ZwsVarSnapshotManager.class));

    private ConcurrentMap<String, ZwsVarBlock> snapshots = new ConcurrentHashMap<>();

    @Override
    public String name() {
        return "variable";
    }

    @Override
    public ConcurrentMap<String, ZwsVarBlock> snapshots() {
        return snapshots;
    }

    @Override
    public Logger logger() {
        return logger;
    }

    @Override
    public void snapshot0(String snapshotName, Map<String, Object> args) {
        snapshots.put(snapshotName, ZwsVar.cloneScenarioBlock());
    }

    @Override
    public void restore0(String snapshotName, Map<String, Object> args) {
        ZwsVar.restoreScenarioBlock(get(snapshotName));
    }
}
